﻿using System;
using Xmef.Interfaces;

namespace Xmef.Library
{
    public static class PluginHelper
    {
        public static bool GetInvocationList(EventHandler<PluginEventArgs> source, EventHandler<PluginEventArgs> value)
        {
            return FindDelegate(source, value);
        }

        public static bool GetInvocationList(EventHandler<PluginHostEventArgs> source, EventHandler<PluginHostEventArgs> value)
        {
            return FindDelegate(source, value);
        }

        private static bool FindDelegate(MulticastDelegate source, Delegate value)
        {
            if (source != null)
            {
                foreach (Delegate eventDelegate in source.GetInvocationList())
                {
                    if (eventDelegate == (Delegate)value)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}
